package com.study.mybatis.plugins;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

/**
 * @author yuantongqin
 * 2021/8/2
 **/
public class InterceptorChain {

    private final List<Interceptor> interceptors = new ArrayList<>();

    public Object pluginAll(Object target){
        for (Interceptor interceptor : interceptors) {
            target = interceptor.plugin(target);
        }
        return target;
    }

    public void addIntercept(Interceptor interceptor){
        interceptors.add(interceptor);
    }

    /**
     * 获取interceptor列表
     * @return
     */
    public List<Interceptor> getInterceptors() {
        return Collections.unmodifiableList(interceptors);
    }

}
